<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#49b1f5">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon-180x180-yaowan.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-yaowan.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-yaowan.png">
  <link rel="mask-icon" href="/images/logo-yaowan.svg" color="#49b1f5">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.css">
  <script src="//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"zhouyuqian.com","root":"/","scheme":"Mist","version":"7.7.2","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":"default","style":"flat"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":true,"color":"#49b1f5","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":"ture"},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="内网穿透工具，相比于 tinc 部署更加方便">
<meta property="og:type" content="article">
<meta property="og:title" content="n2n 安装及使用">
<meta property="og:url" content="https://zhouyuqian.com/2022/07/16/n2n/index.html">
<meta property="og:site_name" content="Fitz&#39;s Blog - 快乐学习每一天">
<meta property="og:description" content="内网穿透工具，相比于 tinc 部署更加方便">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-07-16T02:00:55.000Z">
<meta property="article:modified_time" content="2022-08-29T02:00:55.000Z">
<meta property="article:author" content="Fitz">
<meta property="article:tag" content="Geek">
<meta property="article:tag" content="n2n">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://zhouyuqian.com/2022/07/16/n2n/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true
  };
</script>

  <title>n2n 安装及使用 | Fitz's Blog - 快乐学习每一天</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript><!-- hexo-inject:begin --><!-- hexo-inject:end -->

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Fitz's Blog - 快乐学习每一天</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-ariang">

    <a href="/AriaNg/" rel="section"><i class="fa fa-fw fa-cloud-download"></i>AriaNg</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/Starrynightzyq" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://zhouyuqian.com/2022/07/16/n2n/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Fitz">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Fitz's Blog - 快乐学习每一天">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          n2n 安装及使用
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-07-16 10:00:55" itemprop="dateCreated datePublished" datetime="2022-07-16T10:00:55+08:00">2022-07-16</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-08-29 10:00:55" itemprop="dateModified" datetime="2022-08-29T10:00:55+08:00">2022-08-29</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Geek/" itemprop="url" rel="index"><span itemprop="name">Geek</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>4.2k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>4 分钟</span>
            </span>
            <div class="post-description">内网穿透工具，相比于 tinc 部署更加方便</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="n2n-介绍">N2N 介绍</h1>
<h2 id="n2n-的一些相关概念">N2N 的一些相关概念</h2>
<p>N2N 官方对里面的角色有一些定义，在开始部署前，了解这些定义，能够帮助你快速理解这个软件的使用。</p>
<ol type="1">
<li><p>SuperNode 超级节点</p>
<p>SuperNode 相当与注册中心, 它会记录边缘节点的连接信息，告诉各个边缘节点如何去找到其它的边缘节点。如果超级节点发生故障，那么边缘节点之间将不能正常的进行通信。在整个N2N网络中必须至少拥有一个SuperNode。</p></li>
<li><p>Edge 边缘节点</p>
<p>边缘节点是指所有通过 SuperNode 组网而成的节点，无论你处于哪个位置哪种网络环境下，edge节点之间都能进行通信。 一台计算机可以拥有多个edge, 局域网根据子网掩码来决定两台机器是否处于同一个网段，而edge需要添加一组账号密码，在N2N 里面称作 GroupName 和 password ，Group0 和 Group 1 里面的 10.0.0.1 是不一样的。</p></li>
</ol>
<h2 id="项目地址">项目地址</h2>
<p><strong>目前最常用的版本</strong>，也是官方N2N项目重启后，在各路大神的贡献下，一直在维护并不断完善的版本</p>
<p>项目：https://github.com/ntop/n2n</p>
<h1 id="安装-3.0-stable">安装 (3.0-stable)</h1>
<h2 id="ubuntu">Ubuntu</h2>
<ol type="1">
<li><p>安装编译工具</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install cmake libssl-dev</span><br><span class="line">sudo apt-get install build-essential</span><br></pre></td></tr></table></figure></li>
<li><p>编译、安装 N2N</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/ntop/n2n.git</span><br><span class="line"><span class="built_in">cd</span> n2n</span><br><span class="line">git checkout 3.0-stable</span><br><span class="line">./autogen.sh</span><br><span class="line">./configure</span><br><span class="line">make</span><br><span class="line">sudo make install</span><br></pre></td></tr></table></figure>
<h2 id="openwrt">OpenWrt</h2></li>
</ol>
<p>在github找到一个别人编译好的</p>
<p>https://github.com/csrutil/n2n</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wget https://github.com/csrutil/n2n/releases/download/3.0.0/n2n-edge_3.0.0-1_aarch64_generic.ipk</span><br><span class="line">opkg install ./n2n-edge_3.0.0-1_aarch64_generic.ipk</span><br></pre></td></tr></table></figure>
<h2 id="mac-macos-big-sur-11.6.6">Mac (macOS Big Sur 11.6.6)</h2>
<p>安装必要的软件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">brew tap homebrew/cask</span><br><span class="line">brew install tuntap --cask</span><br><span class="line">brew install openssl</span><br><span class="line">brew install cmake</span><br></pre></td></tr></table></figure>
<p>下载 n2n 的源码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/ntop/n2n.git</span><br><span class="line">git checkout 3.0-stable</span><br></pre></td></tr></table></figure>
<p>编译&amp;安装</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> n2n</span><br><span class="line">mkdir -p build</span><br><span class="line"><span class="built_in">cd</span> build</span><br><span class="line">cmake ..</span><br><span class="line">make</span><br><span class="line">sudo make install</span><br></pre></td></tr></table></figure>
<blockquote>
<p>在 <code>make install</code> 的过程中遇到如下错误：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">CMake Error at cmake_install.cmake:79 (file):</span><br><span class="line">  file INSTALL cannot copy file</span><br><span class="line">  <span class="string">&quot;/Users/zhouyuqian/MyDocuments/my_scripts/n2n/build/doc/edge.8.gz&quot;</span> to</span><br><span class="line">  <span class="string">&quot;/usr/share/man/man8/edge.8.gz&quot;</span>: Read-only file system.</span><br></pre></td></tr></table></figure>
<p>需要手动将 <code>cmake_install.cmake</code> 文件中的 <code>/usr/share/</code>替换为 <code>/usr/local/share/</code></p>
</blockquote>
<h1 id="使用网对网">使用（网对网）</h1>
<h2 id="supernode">SuperNode</h2>
<ol type="1">
<li><p>编辑配置文件 <code>/etc/n2n/supernode.conf</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-p=1234</span><br></pre></td></tr></table></figure>
<blockquote>
<p>-p=1234 是supernode的服务端口，防火墙中要放行该端口的tcp和upd</p>
</blockquote></li>
<li><p>编辑systemctl的启动文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo vim /lib/systemd/system/edge.service</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description=n2n supernode process</span><br><span class="line">After=network-online.target syslog.target</span><br><span class="line">Wants=network-online.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=simple</span><br><span class="line">ExecStart=/usr/sbin/supernode /etc/n2n/supernode.conf -f</span><br><span class="line">Restart=on-abnormal</span><br><span class="line">RestartSec=5</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br><span class="line">Alias=</span><br></pre></td></tr></table></figure></li>
<li><p>启动</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl <span class="keyword">enable</span> supernode</span><br><span class="line">sudo systemctl <span class="keyword">start</span> supernode</span><br></pre></td></tr></table></figure>
<p>or（测试时使用）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo supernode /etc/n2n/supernode.conf -v -f</span><br></pre></td></tr></table></figure>
<h2 id="edge">Edge</h2></li>
<li><p>n2n的虚拟网卡必须指定IP</p></li>
<li><p>路由器的局域网网段必须不一样，比如A路由器192.168.31.0/24，B路由器192.168.12.0/24</p></li>
<li><p>必须把n2n的虚拟网卡添加进防火墙n2n（网络&gt;&gt;&gt;接口，添加新接口，不配置协议，防火墙区域指定n2n）</p></li>
<li><p>新建防火墙规则：</p></li>
</ol>
<h3 id="openwrt路由器a-所在局域网192.168.31.024">openwrt路由器A (所在局域网192.168.31.0/24)</h3>
<p>Edit <code>/etc/n2n/edge.conf</code> and add the following</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">-d=n2n0</span><br><span class="line">-c=n2n_net0</span><br><span class="line">-k=&lt;encryption key&gt;</span><br><span class="line">-a=10.10.10.3/24</span><br><span class="line">-p=53001</span><br><span class="line">-l=&lt;super node ip&gt;:&lt;port&gt;</span><br><span class="line">-r</span><br><span class="line">-n=192.168.12.0/24:10.10.10.2</span><br></pre></td></tr></table></figure>
<blockquote>
<p>-d: TAP device name (网卡名)</p>
<p>-c: n2n community name the edge belongs to</p>
<p>-k: encryption key (ASCII)</p>
<p>-a: 设置此N2N网络中，本机的IP地址</p>
<p>-p: fixed local UDP port and optionally bind to the</p>
<p>-l: supernode ip address or name, and port</p>
</blockquote>
<p>启动n2n</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">edge /etc/n2n/edge.conf -f</span><br></pre></td></tr></table></figure>
<p>or</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/edge <span class="built_in">enable</span></span><br><span class="line">/etc/init.d/edge start</span><br></pre></td></tr></table></figure>
<h3 id="openwrt路由器b-所在局域网192.168.12.024">openwrt路由器B (所在局域网192.168.12.0/24)</h3>
<p>Edit <code>/etc/n2n/supernode.conf</code> and add the following</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">-d=n2n0</span><br><span class="line">-c=n2n_net0</span><br><span class="line">-k=&lt;encryption key&gt;</span><br><span class="line">-a=10.10.10.2/24</span><br><span class="line">-p=53001</span><br><span class="line">-l=&lt;super node ip&gt;:&lt;port&gt;</span><br><span class="line">-r</span><br><span class="line">-n=192.168.31.0/24:10.10.10.3</span><br></pre></td></tr></table></figure>
<h3 id="mac">Mac</h3>
<p>创建conf文件 <code>/etc/n2n/edge.conf</code>，内容如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-c=n2n_net0</span><br><span class="line">-k=&lt;encryption key&gt;</span><br><span class="line">-a=10.10.10.4/24</span><br><span class="line">-p=53001</span><br><span class="line">-l=&lt;super node ip&gt;:&lt;port&gt;</span><br></pre></td></tr></table></figure>
<p>启动 n2n</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo edge /etc/n2n/edge.conf</span><br><span class="line"><span class="comment"># or</span></span><br><span class="line">sudo edge /etc/n2n/edge.conf -f </span><br></pre></td></tr></table></figure>
<p>创建启动脚本 <code>n2nup.sh</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">DelRoute</span></span>()&#123;</span><br><span class="line">    sudo route delete 10.10.10.0/24</span><br><span class="line">    sudo route delete 192.168.12.0/24</span><br><span class="line">    sudo route delete 192.168.31.0/24</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">SetRoute</span></span>()&#123;</span><br><span class="line">    sudo route -n add -net 192.168.12.0 -netmask 255.255.255.0 10.10.10.2</span><br><span class="line">    <span class="comment"># sudo route -n add -net 192.168.31.0 -netmask 255.255.255.0 10.10.10.3</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">CheckStatus</span></span>()&#123;</span><br><span class="line">    <span class="keyword">if</span> [ `grep -c <span class="string">&quot;OK&quot;</span> <span class="string">&quot;/var/log/n2n/edge.log&quot;</span>` -ne <span class="string">&#x27;0&#x27;</span> ]</span><br><span class="line">    <span class="keyword">then</span></span><br><span class="line">        <span class="built_in">echo</span> <span class="string">&quot;OK&quot;</span></span><br><span class="line">        <span class="built_in">return</span> 1</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        <span class="built_in">echo</span> <span class="string">&quot;wait for connection&quot;</span></span><br><span class="line">        <span class="built_in">return</span> 0</span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">DelRoute</span><br><span class="line">sudo edge /etc/n2n/edge.conf -f &gt; /var/<span class="built_in">log</span>/n2n/edge.log  2&gt;&amp;1 &amp;</span><br><span class="line"><span class="keyword">while</span> :</span><br><span class="line"><span class="keyword">do</span></span><br><span class="line">    CheckStatus</span><br><span class="line">    <span class="keyword">if</span> [ $? == <span class="string">&#x27;0&#x27;</span> ];<span class="keyword">then</span></span><br><span class="line">        sleep 2</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        <span class="built_in">break</span></span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line"><span class="keyword">done</span></span><br><span class="line">sleep 2</span><br><span class="line">SetRoute</span><br></pre></td></tr></table></figure>
<p>创建停止脚本 <code>n2ndown.sh</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line">sudo route delete 10.10.10.0/24</span><br><span class="line">sudo route -v delete -net 192.168.12.0 -gateway 10.10.10.2</span><br><span class="line">sudo route -v delete -net 192.168.31.0 -gateway 10.10.10.3</span><br><span class="line">ps -A | grep n2n | grep -v grep | grep -v n2ndown | awk <span class="string">&#x27;&#123;print $1&#125;&#x27;</span> | xargs -n 1 sudo <span class="built_in">kill</span> -9</span><br></pre></td></tr></table></figure>
<h3 id="ubuntu-1">Ubuntu</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo vim /lib/systemd/system/edge.service.</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description=n2n edge process</span><br><span class="line">After=network-online.target syslog.target</span><br><span class="line">Wants=network-online.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=simple</span><br><span class="line">ExecStart=/usr/sbin/edge /etc/n2n/edge.conf -f</span><br><span class="line">Restart=on-abnormal</span><br><span class="line">RestartSec=5</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br><span class="line">Alias=edge.service</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------The end of this article&nbsp;<i class="fa fa-paw"></i>&nbsp;Thank you for your reading-------</div>
    
</div>
      
    </div>
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Fitz
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://zhouyuqian.com/2022/07/16/n2n/" title="n2n 安装及使用">https://zhouyuqian.com/2022/07/16/n2n/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Geek/" <i class="fa fa-tag"></i> Geek</a>
              <a href="/tags/n2n/" <i class="fa fa-tag"></i> n2n</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2022/05/15/uvm-2/" rel="prev" title="uvm-2">
      <i class="fa fa-chevron-left"></i> uvm-2
    </a></div>
      <div class="post-nav-item"></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#n2n-%E4%BB%8B%E7%BB%8D"><span class="nav-number">1.</span> <span class="nav-text">N2N 介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#n2n-%E7%9A%84%E4%B8%80%E4%BA%9B%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5"><span class="nav-number">1.1.</span> <span class="nav-text">N2N 的一些相关概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%A1%B9%E7%9B%AE%E5%9C%B0%E5%9D%80"><span class="nav-number">1.2.</span> <span class="nav-text">项目地址</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AE%89%E8%A3%85-3.0-stable"><span class="nav-number">2.</span> <span class="nav-text">安装 (3.0-stable)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#ubuntu"><span class="nav-number">2.1.</span> <span class="nav-text">Ubuntu</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#openwrt"><span class="nav-number">2.2.</span> <span class="nav-text">OpenWrt</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#mac-macos-big-sur-11.6.6"><span class="nav-number">2.3.</span> <span class="nav-text">Mac (macOS Big Sur 11.6.6)</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8%E7%BD%91%E5%AF%B9%E7%BD%91"><span class="nav-number">3.</span> <span class="nav-text">使用（网对网）</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#supernode"><span class="nav-number">3.1.</span> <span class="nav-text">SuperNode</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#edge"><span class="nav-number">3.2.</span> <span class="nav-text">Edge</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#openwrt%E8%B7%AF%E7%94%B1%E5%99%A8a-%E6%89%80%E5%9C%A8%E5%B1%80%E5%9F%9F%E7%BD%91192.168.31.024"><span class="nav-number">3.2.1.</span> <span class="nav-text">openwrt路由器A (所在局域网192.168.31.0&#x2F;24)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#openwrt%E8%B7%AF%E7%94%B1%E5%99%A8b-%E6%89%80%E5%9C%A8%E5%B1%80%E5%9F%9F%E7%BD%91192.168.12.024"><span class="nav-number">3.2.2.</span> <span class="nav-text">openwrt路由器B (所在局域网192.168.12.0&#x2F;24)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#mac"><span class="nav-number">3.2.3.</span> <span class="nav-text">Mac</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ubuntu-1"><span class="nav-number">3.2.4.</span> <span class="nav-text">Ubuntu</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Fitz"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Fitz</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">78</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">52</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/Starrynightzyq" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Starrynightzyq" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:starrynightzyq@gmail.com" title="E-Mail → mailto:starrynightzyq@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://space.bilibili.com/57711842" title="Bilibili → https:&#x2F;&#x2F;space.bilibili.com&#x2F;57711842" rel="noopener" target="_blank"><i class="fa fa-fw fa-custom bilibili"></i>Bilibili</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://wpa.qq.com/msgrd?v=3&uin=2421854978&site=qq&menu=yes" title="QQ → http:&#x2F;&#x2F;wpa.qq.com&#x2F;msgrd?v&#x3D;3&amp;uin&#x3D;2421854978&amp;site&#x3D;qq&amp;menu&#x3D;yes" rel="noopener" target="_blank"><i class="fa fa-fw fa-custom qq"></i>QQ</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://leiblog.wang/" title="http:&#x2F;&#x2F;leiblog.wang" rel="noopener" target="_blank">Lei Blog</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        
  <div class="beian"><a href="http://beian.miit.gov.cn/" rel="noopener" target="_blank">苏ICP备20042287号 </a>
  </div>

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Fitz</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">251k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">3:48</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v5.3.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> v7.7.2
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/theme-next/theme-next-pjax@0/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.getAttribute('pjax') !== null) {
      script.setAttribute('pjax', '');
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

    </div>

  <!-- 页面点击小红心 -->
  <!-- <script type="text/javascript" src="/js/jquery-3.3.1.min.js"></script> -->
  <script type="text/javascript" src="/js/clicklove.js"></script><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</body>
</html>
